package www.openteam.com.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import www.openteam.com.R;

/**
 * Created by kylin on 2016/11/23.
 */

public class pbProductAdapter extends RecyclerView.Adapter<pbProductAdapter.RecyclerViewHolder> {
        private OnItemClickListener mOnItemClickListener;
        private Context mContext;
        private List<String> mNumberList;

        public pbProductAdapter(Context context, List<String> numberList) {
            this.mContext = context;
            this.mNumberList = numberList;
        }

        public interface OnItemClickListener {
            void onItemClick(View view, int position);
        }

        public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
            this.mOnItemClickListener = onItemClickListener;
        }

        @Override
        public pbProductAdapter.RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            RecyclerViewHolder holder = new RecyclerViewHolder(LayoutInflater.from(mContext).inflate(R.layout.popupwindow_, parent, false));
            return holder;
        }

        @Override
        public void onBindViewHolder(final pbProductAdapter.RecyclerViewHolder holder, final int position) {
            holder.nameText.setText(mNumberList.get(position));
            // 如果设置了回调，则设置点击事件
//            if (mOnItemClickListener != null) {
//                holder.numberTextView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        mOnItemClickListener.onItemClick(holder.itemView, holder.getLayoutPosition());
//                    }
//                });
//            }

        }

        @Override
        public int getItemCount() {
            return mNumberList.size();
        }

        public class RecyclerViewHolder extends RecyclerView.ViewHolder {
            TextView nameText;

            public RecyclerViewHolder(View itemView) {
                super(itemView);
                nameText = (TextView) itemView.findViewById(R.id.tv_pdproduct);
            }
        }
    }

